package SwingComponents;

import Connection.FileWorldCreator;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class TransparentPanel extends JPanel {

    private Image image;

    public TransparentPanel() {
        super();
        this.setOpaque(false);
    }

    public void setBackgroundImage(Image image) {
        this.image = image;
    }

    public Image createImage(String path) {
        try {
            Image image2 = ImageIO.read(new File(path));
            if (image2 != null) {
                return image2;
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
        } catch (IOException ex) {
            try {
                File file = new File("C:/TransparentPanel_createImage.txt");
                file.createNewFile();
            } catch (IOException ex1) {
                Logger.getLogger(FileWorldCreator.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        return null;
    }

    public Image createImage(URL url) {
        try {
            Image image2 = ImageIO.read(url);
            return image2;
        } catch (Exception e) {
        }
        return null;
    }

    @Override
    public void paint(Graphics g) {
        if (image != null) {
            g.drawImage(image, 0, 0, null);
        }
        super.paint(g);

    }
}
